package com.example.bishe.mapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.example.bishe.entity.Message;
import com.example.bishe.entity.User;
import com.example.bishe.entity.UserRoom;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author LDH
 * @since 2022/11/30
 */
@Mapper
public interface UserRoomMapper extends BaseMapper<UserRoom> {

    @Select("SELECT * FROM `user` WHERE id IN (SELECT user_id FROM user_room WHERE room_id=#{roomId})")
    IPage<User> getUserByRoom(
            IPage<User> page,
            @Param("roomId") Long roomId
    );

    @Select("SELECT * FROM user_room WHERE user_id=#{userId} AND room_id=#{roomId}")
    UserRoom getUserRoomByOne(@Param("userId") Long userId, @Param("roomId") Long roomId);

}
